package base64AndURL.test;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class URLCode {


    public static void main(String[] args) {
        String s = "https://www.baidu.com?word=黑洞";
        s = URLEnCode(s);
        System.out.println(s);
        s = URLDeCode(s);
        System.out.println(s);

    }

    static String URLEnCode(String s) {

        try {
            return URLEncoder.encode(s, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

    static String URLDeCode(String s) {
        try {
            return URLDecoder.decode(s, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
}
